﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using OntologyUtility.Xml;

namespace OntologyUtility
{
    public class Node
    {
        [XmlNodeTypeAttribute(System.Xml.XmlNodeType.Attribute)]
        public String Name { get; set; }
        [XmlNodeTypeAttribute(System.Xml.XmlNodeType.Attribute)]
        public String Type { get ; set; }
        [XmlNodeTypeAttribute(System.Xml.XmlNodeType.Attribute)]
        public int Weight { get; set; }
        [XmlNodeTypeAttribute(System.Xml.XmlNodeType.Attribute)]
        public String Alias { get; set; }


        public ArrayList Childs {get; set;}
        private Node father = null;
        

        
        
        public Node()
        {
            Childs = new ArrayList();
            Name = "";
            Type = "";
            Alias = "";
            Weight = 0;
        }

        public override string ToString()
        {
            String sReturn =
                "Name: " + this.Name +
                " Type: " + Type + ((this.Childs.Count == 0) ? "" : " Child: [");
            
            int index = 1;
            int max = Childs.Count;
            foreach (Node node in this.Childs)
            {
                sReturn += (max == index ++) ? (node + "]") : (node + ", ");
            }

            return sReturn;
        }

        public Node Father
        {
            get { return father; }
            set { father = value; }
        }

       
        public static int CompareNodeByWeight(int x, int y)
        {
            return x.CompareTo(y);
        }

        public static int CompareNodeByWeight(Node x, Node y)
        {
            return x.Weight.CompareTo(y.Weight);
        }

        public int CompareNodeByWeight(Node _node) {
            return this.Weight.CompareTo(_node.Weight);
        }
    }
}
